package net.uman.web;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;


import net.uman.framework.io.FileManagerFactory;
import net.uman.framework.io.IFile;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Namespace;

import com.opensymphony.xwork2.ActionSupport;
/**
 * 附件下载
 * @author lihengjun
 *
 */
@Namespace("/manager")
public class ResourceDownloaderAction extends ActionSupport {
	private static final long serialVersionUID = 1L;
	private Long attachmentId;
	private String filePathName;

	private InputStream inputStream;
	
	private String fileName = "未命名";

	public String execute() {
		return "success";
	}
	/**
	 * 下载附件
	 * @return
	 * @throws FileNotFoundException
	 */
	public InputStream getInputStream() throws FileNotFoundException{
		//inputStream = ServletActionContext.getServletContext().getResourceAsStream("/"+filePathName);
		
			File file = new File(filePathName);
			String thisFileName = file.getName();
			System.err.println(file.exists()+"====="+file.getTotalSpace()/(1024*1024)); 
			fileName += thisFileName.substring(thisFileName.lastIndexOf("."));
			return new FileInputStream(file);
	}
	
	public void setAttachmentId(Long attachmentId) {
		this.attachmentId = attachmentId;
	}
	public String getFilePathName() {
		return filePathName;
	}
	public void setFilePathName(String filePathName) {
		this.filePathName = filePathName;
	}
	public Long getAttachmentId() {
		return attachmentId;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
}
